#ifndef __SPACEMIT_SPM8821_H__
#define __SPACEMIT_SPM8821_H__

#define SPACEMIT_SPM8821_ID_REG		0x0
#define SPACEMIT_SPM8821_MAX_REG	0xA8

#define SPACEMIT_SPM8821_ID		0x2

#define SPM8821_BUCK_VSEL_MASK		0xff
#define SMP8821_BUCK_EN_MASK		0x1

#define SPM8821_BUCK1_CTRL_REG		0x47
#define SPM8821_BUCK2_CTRL_REG		0x4a
#define SPM8821_BUCK3_CTRL_REG		0x4d
#define SPM8821_BUCK4_CTRL_REG		0x50
#define SPM8821_BUCK5_CTRL_REG		0x53
#define SPM8821_BUCK6_CTRL_REG		0x56

#define SPM8821_BUCK1_VSEL_REG		0x48
#define SPM8821_BUCK2_VSEL_REG		0x4b
#define SPM8821_BUCK3_VSEL_REG		0x4e
#define SPM8821_BUCK4_VSEL_REG		0x51
#define SPM8821_BUCK5_VSEL_REG		0x54
#define SPM8821_BUCK6_VSEL_REG		0x57

#define SPM8821_BUCK1_SVSEL_REG		0x49
#define SPM8821_BUCK2_SVSEL_REG		0x4c
#define SPM8821_BUCK3_SVSEL_REG		0x4f
#define SPM8821_BUCK4_SVSEL_REG		0x52
#define SPM8821_BUCK5_SVSEL_REG		0x55
#define SPM8821_BUCK6_SVSEL_REG		0x58

#define SPM8821_BUCK_SVSEL_MASK		0xff

#define SPM8821_ALDO1_CTRL_REG		0x5b
#define SPM8821_ALDO2_CTRL_REG		0x5e
#define SPM8821_ALDO3_CTRL_REG		0x61
#define SPM8821_ALDO4_CTRL_REG		0x64

#define SPM8821_ALDO1_VOLT_REG		0x5c
#define SPM8821_ALDO2_VOLT_REG		0x5f
#define SPM8821_ALDO3_VOLT_REG		0x62
#define SPM8821_ALDO4_VOLT_REG		0x65

#define SPM8821_ALDO1_SVOLT_REG		0x5d
#define SPM8821_ALDO2_SVOLT_REG		0x60
#define SPM8821_ALDO3_SVOLT_REG		0x63
#define SPM8821_ALDO4_SVOLT_REG		0x66
#define SPM8821_ALDO_SVSEL_MASK		0x3f

#define SPM8821_ALDO_EN_MASK		0x1
#define SPM8821_ALDO_VSEL_MASK		0x3f

#define SPM8821_DLDO1_CTRL_REG		0x67
#define SPM8821_DLDO2_CTRL_REG		0x6a
#define SPM8821_DLDO3_CTRL_REG		0x6d
#define SPM8821_DLDO4_CTRL_REG		0x70
#define SPM8821_DLDO5_CTRL_REG		0x73
#define SPM8821_DLDO6_CTRL_REG		0x76
#define SPM8821_DLDO7_CTRL_REG		0x79

#define SPM8821_DLDO1_VOLT_REG		0x68
#define SPM8821_DLDO2_VOLT_REG		0x6b
#define SPM8821_DLDO3_VOLT_REG		0x6e
#define SPM8821_DLDO4_VOLT_REG		0x71
#define SPM8821_DLDO5_VOLT_REG		0x74
#define SPM8821_DLDO6_VOLT_REG		0x77
#define SPM8821_DLDO7_VOLT_REG		0x7a

#define SPM8821_DLDO1_SVOLT_REG		0x69
#define SPM8821_DLDO2_SVOLT_REG		0x6c
#define SPM8821_DLDO3_SVOLT_REG		0x6f
#define SPM8821_DLDO4_SVOLT_REG		0x72
#define SPM8821_DLDO5_SVOLT_REG		0x75
#define SPM8821_DLDO6_SVOLT_REG		0x78
#define SPM8821_DLDO7_SVOLT_REG		0x7b

#define SPM8821_DLDO_SVSEL_MASK		0x3f

#define SPM8821_DLDO_EN_MASK		0x1
#define SPM8821_DLDO_VSEL_MASK		0x3f

#define SPM8821_SWITCH_CTRL_REG		0x59
#define SPM8821_SWTICH_EN_MASK		0x1

/* Watchdog Timer Registers */
#define SPM8821_WDT_CTRL           0x44
#define SPM8821_PWR_CTRL0          0x7C
#define SPM8821_PWR_CTRL2          0x7E

/* Watchdog Timer Control Bits */
#define SPM8821_WDT_CLEAR_STATUS     0x1
#define SPM8821_SW_RST               0x2
#define SPM8821_WDT_RESET_ENABLE     0x80
#define SPM8821_WDT_ENABLE           0x8
#define SPM8821_WDT_TIMEOUT_1S       0x0
#define SPM8821_WDT_TIMEOUT_4S       0x1
#define SPM8821_WDT_TIMEOUT_8S       0x2
#define SPM8821_WDT_TIMEOUT_16S      0x3

enum SPM8821_buck_reg {
	SPM8821_ID_DCDC1,
	SPM8821_ID_DCDC2,
	SPM8821_ID_DCDC3,
	SPM8821_ID_DCDC4,
	SPM8821_ID_DCDC5,
	SPM8821_ID_DCDC6,
};

enum SPM8821_ldo_reg {
	SPM8821_ID_LDO1,
	SPM8821_ID_LDO2,
	SPM8821_ID_LDO3,
	SPM8821_ID_LDO4,
	SPM8821_ID_LDO5,
	SPM8821_ID_LDO6,
	SPM8821_ID_LDO7,
	SPM8821_ID_LDO8,
	SPM8821_ID_LDO9,
	SPM8821_ID_LDO10,
	SPM8821_ID_LDO11,
};

enum SPM8821_switch_reg {
	SPM8821_ID_SWITCH1,
};

#define SPM8821_BUCK_LINER_RANGE					\
static const struct pm8xx_linear_range spm8821_buck_ranges[] = {		\
        REGULATOR_LINEAR_RANGE(500000, 0x0, 0xaa, 5000),		\
        REGULATOR_LINEAR_RANGE(1375000, 0xab, 0xfe, 25000),		\
};

#define SPM8821_LDO_LINER_RANGE						\
static const struct pm8xx_linear_range spm8821_ldo_ranges[] = {		\
        REGULATOR_LINEAR_RANGE(500000, 0xb, 0x7f, 25000),		\
};

#define SPM8821_SWITCH_LINER_RANGE					\
static const struct pm8xx_linear_range spm8821_switch_ranges[] = {		\
};

#define SPM8821_REGULATOR_BUCK_DESC		\
static const struct pm8xx_buck_desc spm8821_buck_desc[] = {	\
	/* BUCK */		\
	PM8XX_DESC_COMMON(SPM8821_ID_DCDC1, "DCDC_REG1",			\
			255, SPM8821_BUCK1_VSEL_REG, SPM8821_BUCK_VSEL_MASK,	\
			SPM8821_BUCK1_CTRL_REG, SMP8821_BUCK_EN_MASK,		\
			SPM8821_BUCK1_SVSEL_REG, SPM8821_BUCK_SVSEL_MASK,	\
			spm8821_buck_ranges),	\
	\
	PM8XX_DESC_COMMON(SPM8821_ID_DCDC2, "DCDC_REG2",				\
			255, SPM8821_BUCK2_VSEL_REG, SPM8821_BUCK_VSEL_MASK,	\
			SPM8821_BUCK2_CTRL_REG, SMP8821_BUCK_EN_MASK,	\
			SPM8821_BUCK2_SVSEL_REG, SPM8821_BUCK_SVSEL_MASK,	\
			spm8821_buck_ranges),	\
	\
	PM8XX_DESC_COMMON(SPM8821_ID_DCDC3, "DCDC_REG3",				\
			255, SPM8821_BUCK3_VSEL_REG, SPM8821_BUCK_VSEL_MASK,	\
			SPM8821_BUCK3_CTRL_REG, SMP8821_BUCK_EN_MASK,	\
			SPM8821_BUCK3_SVSEL_REG, SPM8821_BUCK_SVSEL_MASK,	\
			spm8821_buck_ranges),	\
	\
	PM8XX_DESC_COMMON(SPM8821_ID_DCDC4, "DCDC_REG4",				\
			255, SPM8821_BUCK4_VSEL_REG, SPM8821_BUCK_VSEL_MASK,	\
			SPM8821_BUCK4_CTRL_REG, SMP8821_BUCK_EN_MASK,	\
			SPM8821_BUCK4_SVSEL_REG, SPM8821_BUCK_SVSEL_MASK,	\
			spm8821_buck_ranges),	\
	\
	PM8XX_DESC_COMMON(SPM8821_ID_DCDC5, "DCDC_REG5",				\
			255, SPM8821_BUCK5_VSEL_REG, SPM8821_BUCK_VSEL_MASK,	\
			SPM8821_BUCK5_CTRL_REG, SMP8821_BUCK_EN_MASK,	\
			SPM8821_BUCK5_SVSEL_REG, SPM8821_BUCK_SVSEL_MASK,	\
			spm8821_buck_ranges),	\
	\
	PM8XX_DESC_COMMON(SPM8821_ID_DCDC6, "DCDC_REG6",				\
			255, SPM8821_BUCK6_VSEL_REG, SPM8821_BUCK_VSEL_MASK,	\
			SPM8821_BUCK6_CTRL_REG, SMP8821_BUCK_EN_MASK,	\
			SPM8821_BUCK6_SVSEL_REG, SPM8821_BUCK_SVSEL_MASK,	\
			spm8821_buck_ranges),	\
};

#define SPM8821_REGULATOR_LDO_DESC		\
static const struct pm8xx_buck_desc spm8821_ldo_desc[] = {	\
	/* ALDO */	\
	PM8XX_DESC_COMMON(SPM8821_ID_LDO1, "LDO_REG1",	\
			128, SPM8821_ALDO1_VOLT_REG, SPM8821_ALDO_VSEL_MASK,	\
			SPM8821_ALDO1_CTRL_REG, SPM8821_ALDO_EN_MASK,		\
			SPM8821_ALDO1_SVOLT_REG, SPM8821_ALDO_SVSEL_MASK,	\
			spm8821_ldo_ranges),	\
	\
	PM8XX_DESC_COMMON(SPM8821_ID_LDO2, "LDO_REG2",\
			128, SPM8821_ALDO2_VOLT_REG, SPM8821_ALDO_VSEL_MASK,	\
			SPM8821_ALDO2_CTRL_REG, SPM8821_ALDO_EN_MASK,		\
			SPM8821_ALDO2_SVOLT_REG, SPM8821_ALDO_SVSEL_MASK,	\
			spm8821_ldo_ranges),	\
	\
	PM8XX_DESC_COMMON(SPM8821_ID_LDO3, "LDO_REG3",	\
			128, SPM8821_ALDO3_VOLT_REG, SPM8821_ALDO_VSEL_MASK,	\
			SPM8821_ALDO3_CTRL_REG, SPM8821_ALDO_EN_MASK,		\
			SPM8821_ALDO3_SVOLT_REG, SPM8821_ALDO_SVSEL_MASK,	\
			spm8821_ldo_ranges),	\
	\
	PM8XX_DESC_COMMON(SPM8821_ID_LDO4, "LDO_REG4",\
			128, SPM8821_ALDO4_VOLT_REG, SPM8821_ALDO_VSEL_MASK,	\
			SPM8821_ALDO4_CTRL_REG, SPM8821_ALDO_EN_MASK,		\
			SPM8821_ALDO4_SVOLT_REG, SPM8821_ALDO_SVSEL_MASK,	\
			spm8821_ldo_ranges),	\
	\
	/* DLDO */	\
	PM8XX_DESC_COMMON(SPM8821_ID_LDO5, "LDO_REG5",\
			128, SPM8821_DLDO1_VOLT_REG, SPM8821_DLDO_VSEL_MASK,	\
			SPM8821_DLDO1_CTRL_REG, SPM8821_DLDO_EN_MASK,		\
			SPM8821_DLDO1_SVOLT_REG, SPM8821_DLDO_SVSEL_MASK,	\
			spm8821_ldo_ranges),	\
	\
	PM8XX_DESC_COMMON(SPM8821_ID_LDO6, "LDO_REG6",\
			128, SPM8821_DLDO2_VOLT_REG, SPM8821_DLDO_VSEL_MASK,	\
			SPM8821_DLDO2_CTRL_REG, SPM8821_DLDO_EN_MASK,		\
			SPM8821_DLDO2_SVOLT_REG, SPM8821_DLDO_SVSEL_MASK,	\
			spm8821_ldo_ranges),	\
	\
	PM8XX_DESC_COMMON(SPM8821_ID_LDO7, "LDO_REG7",\
			128, SPM8821_DLDO3_VOLT_REG, SPM8821_DLDO_VSEL_MASK,	\
			SPM8821_DLDO3_CTRL_REG, SPM8821_DLDO_EN_MASK,		\
			SPM8821_DLDO3_SVOLT_REG, SPM8821_DLDO_SVSEL_MASK,	\
			spm8821_ldo_ranges),	\
	\
	PM8XX_DESC_COMMON(SPM8821_ID_LDO8, "LDO_REG8",\
			128, SPM8821_DLDO4_VOLT_REG, SPM8821_DLDO_VSEL_MASK,	\
			SPM8821_DLDO4_CTRL_REG, SPM8821_DLDO_EN_MASK,		\
			SPM8821_DLDO4_SVOLT_REG, SPM8821_DLDO_SVSEL_MASK,	\
			spm8821_ldo_ranges),	\
	\
	PM8XX_DESC_COMMON(SPM8821_ID_LDO9, "LDO_REG9",\
			128, SPM8821_DLDO5_VOLT_REG, SPM8821_DLDO_VSEL_MASK,	\
			SPM8821_DLDO5_CTRL_REG, SPM8821_DLDO_EN_MASK,		\
			SPM8821_DLDO5_SVOLT_REG, SPM8821_DLDO_SVSEL_MASK,	\
			spm8821_ldo_ranges),	\
	\
	PM8XX_DESC_COMMON(SPM8821_ID_LDO10, "LDO_REG10",\
			128, SPM8821_DLDO6_VOLT_REG, SPM8821_DLDO_VSEL_MASK,	\
			SPM8821_DLDO6_CTRL_REG, SPM8821_DLDO_EN_MASK,		\
			SPM8821_DLDO6_SVOLT_REG, SPM8821_DLDO_SVSEL_MASK,	\
			spm8821_ldo_ranges),	\
	\
	PM8XX_DESC_COMMON(SPM8821_ID_LDO11, "LDO_REG11",\
			128, SPM8821_DLDO7_VOLT_REG, SPM8821_DLDO_VSEL_MASK,	\
			SPM8821_DLDO7_CTRL_REG, SPM8821_DLDO_EN_MASK,		\
			SPM8821_DLDO7_SVOLT_REG, SPM8821_DLDO_SVSEL_MASK,	\
			spm8821_ldo_ranges),	\
	\
};

#define SPM8821_REGULATOR_SWITCH_DESC		\
static const struct pm8xx_buck_desc spm8821_switch_desc[] = {	\
	/* PWR SWITCH */	\
	PM8XX_DESC_COMMON(SPM8821_ID_SWITCH1, "SWITCH_REG", 0, SPM8821_SWITCH_CTRL_REG, SPM8821_SWTICH_EN_MASK,		\
			0, 0, 0, 0, spm8821_switch_ranges),	\
};

#define SPM8821_REGULATOR_MATCH_DATA					\
struct regulator_match_data spm8821_regulator_match_data = {	\
	.nr_buck_desc = ARRAY_SIZE(spm8821_buck_desc),				\
	.buck_desc = spm8821_buck_desc,						\
	.nr_ldo_desc = ARRAY_SIZE(spm8821_ldo_desc),				\
	.ldo_desc = spm8821_ldo_desc,						\
	.nr_switch_desc = ARRAY_SIZE(spm8821_switch_desc),			\
	.switch_desc = spm8821_switch_desc,					\
	.name = "spm8821",							\
        .max_registers = 0xA8,							\
};

#define DECLEAR_SPM8821_REGULATOR_MATCH_DATA extern struct regulator_match_data spm8821_regulator_match_data;

#endif /* __SPACEMIT_SPM8821_H__ */
